/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2014 Stony Brook University */

/*
 * This file contains definitions of PAL error codes.
 */

#pragma once

#include <stddef.h>

#include "nodiscard.h"

typedef enum NODISCARD {
    PAL_ERROR_SUCCESS = 0,
    PAL_ERROR_NOTIMPLEMENTED = -1,
    PAL_ERROR_NOTDEFINED = -2,
    PAL_ERROR_NOTSUPPORT = -3,
    PAL_ERROR_INVAL = -4,
    PAL_ERROR_TOOLONG = -5,
    PAL_ERROR_DENIED = -6,
    PAL_ERROR_BADHANDLE = -7,
    PAL_ERROR_STREAMEXIST = -8,
    PAL_ERROR_STREAMNOTEXIST = -9,
    PAL_ERROR_STREAMISFILE = -10,
    PAL_ERROR_STREAMISDIR = -11,
    PAL_ERROR_STREAMISDEVICE = -12,
    PAL_ERROR_INTERRUPTED = -13,
    PAL_ERROR_OVERFLOW = -14,
    PAL_ERROR_BADADDR = -15,
    PAL_ERROR_NOMEM = -16,
    PAL_ERROR_INCONSIST = -17,
    PAL_ERROR_TRYAGAIN = -18,
    PAL_ERROR_NOTSERVER = -19,
    PAL_ERROR_NOTCONNECTION = -20,
    PAL_ERROR_CONNFAILED = -21,
    PAL_ERROR_ADDRNOTEXIST = -22,
    PAL_ERROR_AFNOSUPPORT = -23,
    PAL_ERROR_CONNFAILED_PIPE = -24,

#define PAL_ERROR_NATIVE_END   (-PAL_ERROR_CONNFAILED_PIPE)
#define PAL_ERROR_NATIVE_COUNT (PAL_ERROR_NATIVE_END + 1)

#define PAL_ERROR_CRYPTO_START PAL_ERROR_CRYPTO_FEATURE_UNAVAILABLE

    /* Crypto error constants and their descriptions are adapted from mbedtls. */
    PAL_ERROR_CRYPTO_FEATURE_UNAVAILABLE = -100,
    PAL_ERROR_CRYPTO_INVALID_CONTEXT = -101,
    PAL_ERROR_CRYPTO_INVALID_KEY_LENGTH = -102,
    PAL_ERROR_CRYPTO_INVALID_INPUT_LENGTH = -103,
    PAL_ERROR_CRYPTO_INVALID_OUTPUT_LENGTH = -104,
    PAL_ERROR_CRYPTO_BAD_INPUT_DATA = -105,
    PAL_ERROR_CRYPTO_INVALID_PADDING = -106,
    PAL_ERROR_CRYPTO_DATA_MISALIGNED = -107,
    PAL_ERROR_CRYPTO_INVALID_FORMAT = -108,
    PAL_ERROR_CRYPTO_AUTH_FAILED = -109,
    PAL_ERROR_CRYPTO_IO_ERROR = -110,
    PAL_ERROR_CRYPTO_KEY_GEN_FAILED = -111,
    PAL_ERROR_CRYPTO_INVALID_KEY = -112,
    PAL_ERROR_CRYPTO_VERIFY_FAILED = -113,
    PAL_ERROR_CRYPTO_RNG_FAILED = -114,
    PAL_ERROR_CRYPTO_INVALID_DH_STATE = -115,
#define PAL_ERROR_CRYPTO_END PAL_ERROR_CRYPTO_INVALID_DH_STATE
} pal_error_t;

/* err - value of error code, either positive or negative */
const char* pal_strerror(int err);
